#!/usr/bin/groovy
package com.gitee.infrastlabs

import com.cloudbees.groovy.cps.NonCPS

@NonCPS
def getEmpSlave(preffix) {//computers
  for (c in jenkins.model.Jenkins.instance.computers) {
    if (c.node.labelString.contains(preffix) && c.countBusy() == 0) {
	  return c.node.labelString
    }
  }
  return ""
}

/**
  * Returns the path to a temp location of a script from the global library (resources/ subdirectory)
  *
  * @param srcPath path within the resources/ subdirectory of this repo
  * @param destPath destination path (optional)
  * @return path to local file
  */
String copyGlobalLibraryScript(String srcPath, String destPath = null) {
  destPath = destPath ?: createTempLocation(srcPath)
  writeFile file: destPath, text: libraryResource(srcPath)
  echo "copyGlobalLibraryScript: copied ${srcPath} to ${destPath}"
  return destPath
}